<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 商家联合促销
 */
namespace app\allwin\model;
use think\Model;

class AllwinUnmarket extends Model{

    protected $pk = 'id';


    //添加或编辑
    public static function edit(array $param){
        $data = [
            'uid'              => trim($param['uid']),
            'telphone'         => trim($param['telphone']),
            'mycode'           => trim($param['mycode']),
            'tips'             => trim($param['tips']),
            'title'            => trim($param['title']),
            'bonus_types'      => trim($param['bonus_types']),
            'bonus_user_types' => trim($param['bonus_user_types']),
            'share_ratio_user' => trim($param['share_ratio_user']),
            'share_ratio'      => trim($param['share_ratio']),
            'price'            => trim($param['price']),
            'share_img'        => trim($param['share_img']),
            'share_title'      => trim($param['share_title']),
            'share_text'       => trim($param['share_text']),
            'music'            => trim($param['music']),
            'note'             => $param['note'],
            'img'              => $param['img'],
            'imgs'             => json_encode($param['imgs']),
            'start_time'       => strtotime($param['start_time']),
            'end_time'         => strtotime($param['end_time']),
        ];
        if(isset($param['id'])){
            $condition['id']                = $param['id'];
            $condition['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::where($condition)->update($data);
        }else{
            $data['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::insert($data);
        }
    }
}